<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Calendar"%>
<%@page import="shmged.com.shlcm.utils.CmCreateUtil"%>
<%@page import="shmged.com.shlcm.reimbursement.CmCreateReimbursementEntry"%>
<%@page import="java.util.List"%><html >
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@page import="wt.httpgw.URLFactory"%>
<%@include file = "/shmged/jsp/com/shlcm/portal/main/head.jsp" %>
<head>

<title>创建费用报销</title>
<link rel="stylesheet" type="text/css" href="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript">var pageBaseUrl = "<%=baseUrl%>";</script>
<script type="text/javascript" src="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=baseUrl%>shmged/jsp/com/shlcm/portal/js/main.js"></script>
<style type="text/css">
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
 .current a {
            font-size: 20px;
        }

        .over {
            display: none;
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: #f5f5f5;
            opacity:0.5;
            z-index: 1000;
        }

        .layout {
            display: none;
            position: absolute;
            top: 40%;
            left: 40%;
            width: 20%;
            height: 20%;
            z-index: 1001;
            text-align:center;
        }
</style>
</head>
<body>
<%
	Calendar cal = Calendar.getInstance(); 
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	String cdate = sdf.format(cal.getTime()); 
	String year=cdate.substring(0,cdate.indexOf("-"));
	String[] types=CmCreateUtil.getReimbursementType();
	String[] detailTypes=CmCreateUtil.getDetailType();
	List projectNameList=CmCreateReimbursementEntry.getAllProjectName();
%>

<center>
<div style="margin:10px 0;"></div>
	<div  iconCls="icon-kms-related" title="创建费用报销" style="width: 750px; height: 400px; padding: 5px;" id="browseCreateReimbursement" name="browseCreateReimbursement" >
		<center>
		<form method="post" enctype="multipart/form-data" name="createRBForm" id="createRBForm">
	 <div id="p" class="easyui-panel" title="报销单" align="center">		
	 <input  type="hidden" id="create_RefeBursementLife" value="<%=year %>年" name="create_RefeBursementLife"></input>
		<input type="hidden" id="create_ProjectName" name="create_ProjectName"></input>	
		<table  width="600px">
			<tr>
			<td align="right">项目名称:</td>
				<td align="left"><select id="showProjectName">
				<%for(int i=0;i<projectNameList.size();i++) 
				{
				%>
				<option value="<%=projectNameList.get(i) %>"><%=projectNameList.get(i) %></option>
				<% 	
				}%>
				
				</select></td>
				<td align="right">报销周期:</td>
				<td align="left"> <input  type="text" id="create_RefeBursementLife" readonly="readonly" value="<%=year %>年" name="create_RefeBursementLife"></input></td>
			</tr>
			
			<tr>
				<td align="right">发票数:</td>
				<td align="left"><input  type="text"  id="create_InvoiceNum"  name="create_InvoiceNum" class="easyui-numberbox" data-options="onChange: function(value){$('#vv').text(value);}"></input></td>
				<td align="right">报销日期:</td>
				<td align="left"><input  id="create_Time"  name="create_Time" value="<%=cdate %>"  class="easyui-datebox" data-options="formatter:myformatter,parser:myparser"></input></td>
			</tr>
			
			<tr>
				
				<td align="right">报销金额(小写):</td>
				<td align="left"><input type="text"  disabled    id="add_Sum" name="add_Sum"></input><input type="hidden" id="create_Sum" name="create_Sum"></input></td>
				<td align="right">报销金额(大写):</td>
				<td align="left"><input type="text" disabled  id="add_create_Amount" name="add_create_Amount"></input>
					<input type="hidden"  id="create_Amount" name="create_Amount"></input>
				</td>
			</tr>
			<tr>
				<td align="right">单据类型:</td>
				<td align="left"><input type="text" id="create_RefeBursementType"  value="项目报销" readonly="readonly" name="create_RefeBursementType"></input></td>
				<td align="right">付款方式:</td>
				<td align="left"><select id="create_PayMethod" name="create_PayMethod">
						<option value="现金"  >现金</option>
						<option value="银行转账">银行转账</option>
					</select>
				</td>
			</tr>	
		</table>
		</div>
		<div style="margin:10px 0;"></div>
		<div id="p" class="easyui-panel" title="费用明细" align="center" style="height:440px" >
		<table width="600px">
			<tr>
    			<td align="right" width="100px">费用类型:</td>
    			<td align="left">
    				<select id="detailType">
    					
    					<%
    						for(int i=0;i<detailTypes.length;i++)
    						{
    							%>
    							<option value="<%=detailTypes[i] %>"><%=detailTypes[i] %></option>
    							<% 
    						}
    					%>
    				</select>
    			</td>
    			<td align="right" width="100px">金额:</td>
    			<td align="left"><input id="detaiSum" name="detaiSum" class="easyui-numberbox" required data-options="onChange: function(value){$('#vv').text(value);}"></input></td>
    		</tr>
    		<tr>
    			<td align="right">用途:</td>
    			<td align="left"><input type="text" id="detaiTo" class="easyui-validatebox" required data-options="required:true" ></input></td>
    			<td align="right">时间:</td>
    			<td align="left"><input type="text" id="detaiTime" name="detaiTime" class="easyui-datebox"  value="<%=cdate %>" data-options="formatter:myformatter,parser:myparser"></input></td>
    		</tr>
			<tr>
				<td align="right">备注:</td>
				<td colspan="2" align="left"><input type="text" id="detaiDesc" size="35"></input></td>
				<td><input type="button" onclick="appendRBDetail()" value="增加明细"></input></td>
			</tr>
		</table>
		 	<table id="detailTable" class="easyui-datagrid" title="费用明细" style="width:600px;height:290px"
						data-options="rownumbers:true,singleSelect:true,toolbar:'#detailButton',onClickRow: onClickRow">
						<thead>
							<tr>
							<th data-options="field:'type',width:80,align:'center'">费用类型</th>
							<th data-options="field:'amount',width:80,align:'center'">金额</th>
							<th data-options="field:'to',width:80,align:'center'">用途</th>
							<th data-options="field:'time',width:80,align:'center'">时间</th>
							<th data-options="field:'desc',width:240,align:'center'">备注</th>
							</tr>
						</thead>
					</table>
			<div style="margin:10px 0;"></div>
			<div>附件<input type='file' size=40 name='appendixFile"' id="appendixFile" /></div>
					
		<div id="detailButton" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="removeDetail()">删除</a>
		</div>
		
	</div>
			</div>		
			<table>
				<tr>
					<td>
        			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitCreateRBForm()">保存</a>
	    			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeCreateRB()">关闭</a>
					</td>
				</tr>
			</table>
	</form>
		</center>
		
</div>
  <div id="over" class="over"></div>
  <div id="layout" class="layout"><img src="<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/loading.gif" /></div>

</center>
<script type="text/javascript">
function setProjectName()
{
	
}

function showLoading()
{
    document.getElementById("over").style.display = "block";
    document.getElementById("layout").style.display = "block";
}


var editIndex = undefined;


	function appendRBDetail()
	{
		var detailType = document.getElementById("detailType");
		detailType=detailType.options[detailType.selectedIndex].value;
		var detaiSum=$("#detaiSum").val();
		var detaiTo=$("#detaiTo").val();
		
		var detaidesc=$("#detaiDesc").val();
		var detaiTime="";
		var begin=document.getElementsByName("detaiTime");
		for(var i=0;i<begin.length;i++)
		{
			if(begin[i].value!="")
			{
				detaiTime=begin[i].value;
			}
			
		}
		var temp=""
		if(detaiSum==null||detaiSum=="")
		{
			temp="金额";
		}

		if(detaiTo==null||detaiTo=="")
		{

			if(temp.length>0)
			{
				temp=temp+"、";
			}
			temp=temp+"用途";
		}

		if(temp.length>0)
		{
			$.messager.alert('提示',"明细"+temp+"不能为空!");
			return;
		}
		$('#detailTable').datagrid('appendRow',{type:detailType,amount:detaiSum,to:detaiTo,time:detaiTime,desc:detaidesc});
		editIndex = $('#detailTable').datagrid('getRows').length-1;
		$('#detailTable').datagrid('selectRow', editIndex)
						.datagrid('beginEdit', editIndex);
		setSum();
	}

	function submitCreateRBForm()
	{
		var showProjectName = document.getElementById("showProjectName");
		showProjectName=showProjectName.options[showProjectName.selectedIndex].value;
		document.getElementById("create_ProjectName").value=showProjectName;
		showLoading();
		var invoiceNum=document.getElementById("create_InvoiceNum").value;
		//var num= parseFloat(invoiceNum);
		
		
		<%--var create_ProjectNo = $("#create_ProjectNo").val();
		var create_ContactNo = $("#create_ContactNo").val();
		var add_Sum=$("#add_Sum").val();--%>

		document.getElementById("create_Sum").value=document.getElementById("add_Sum").value;
		document.getElementById("create_Amount").value=document.getElementById("add_create_Amount").value;
		<%--if(create_ProjectNo==""||create_ProjectNo==null)
		{
			$.messager.alert('提示',"项目编号不能为空");
			return;
		}
		if(create_ContactNo==""||create_ContactNo==null)
		{
			$.messager.alert('提示',"合同编号不能为空");
			return;
		}
		if(add_Sum==""||add_Sum==null)
		{
			$.messager.alert('提示',"报销金额(小写)不能为空");
			return;
		}--%>
		$('#createRBForm').submit();
	}

	function initCreateRBForm(){
		$("#createRBForm").form({
			url:'<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/jspCreateReimbursement.jsp',
			onSubmit:function (){
			},
			success:function (data){
				if(data.indexOf("ERROR") != -1){
					$.messager.alert('错误',data,'error');
				}else{
					var rows = $("#detailTable").datagrid('getRows');
					if(rows.length==0)
					{
						
						window.location.href='<%=baseUrl %>shmged/jsp/com/shlcm/reimbursement/browseShowReimbursement.jsp?oid='+data;
						
					}else
					{
						createDetail(data);
					}
					
					
				}
				hideProcessMsg("prince_process_ques");
			},
			onLoadError:function (){
				hideProcessMsg("prince_process_ques");
			}
		});
	}

	function createDetail(oid)
	{

		var rows = $("#detailTable").datagrid('getRows');
		var infos="";
		for(var i=0; i<rows.length; i++){
			infos+=rows[i].type+"__"+rows[i].amount+"__"+rows[i].to+"__"+rows[i].time+"__"+rows[i].desc+"###";
		}
		var url="<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/jspCreateReimbursementDetail.jsp";
		var idata = {oid:oid,info:infos};
		  jQuery.post(url,idata,function (data){
			  window.location.href='<%=baseUrl %>shmged/jsp/com/shlcm/reimbursement/browseShowReimbursement.jsp?oid='+oid;
	        });
	}
	function closeCreateRB()
	{
		window.close();
		
	}
	

	/*添加附件功能*/
	function addDetailed(htmlId){
		//alert("appendixFileId :"+htmlId);
		var $div = $("#"+htmlId);
		var len = $div.children("input[type='file']") + 1;
		//alert("len :"+len);
		$div.append("<div><input type='file' size=60 name='appendixFile_"+len+"' /><input type='button' value='-' onclick='removeDetailed(this)'></input></div>");
	}
	function removeDetailed(obj){
		var temp = $(obj);
		temp.parent("div").remove(); 
	}

	function onClickRow(index)
	{
		editIndex=index;
	}
	
	function removeDetail(index)
	{

			$('#detailTable').datagrid('cancelEdit', editIndex)
			.datagrid('deleteRow', editIndex);
			setSum();
	}


	function setSum()
	{
		var rows = $("#detailTable").datagrid('getRows');
		var infos="";
		for(var i=0; i<rows.length; i++){
			infos=Number(infos)+Number(rows[i].amount);
		}
		document.getElementById("add_Sum").value=infos;
		document.getElementById("add_create_Amount").value=convertCurrency(infos);
	}
	
	initCreateRBForm();
</script>
</body>

</html>


